__author__ = 'YinDu'

import os
from pathlib import Path

BASE_DIR = Path(__file__).resolve().parent.parent


def to_path(value):
    """
        topath: Corresponding to the file
        :return: The file path
    """
    return os.path.join(BASE_DIR, value)


class FileSize:
    def file_size(self, img):
        """
            img: file
            :return: file size
        """
        img.seek(0, os.SEEK_END)
        return img.tell()


class WithOpenText:
    def with_open_text_write(self, title, state, value=None):
        """
            title: The file path
            value: Written content
            state: Mode of operation
        """
        with open(title, state) as some_text:
            some_text.write(str(value))
        return True

    def with_open_text_read(self, title, state):
        """
            title: The file path
            state: Mode of operation
            :return: Data in file
        """
        with open(title, state) as some_text:
            data_text = some_text.read()
            if data_text != '':
                data_text = eval(data_text)
        return data_text


wot = WithOpenText()
